#include "SemanticNodeBlockModelInstance.h"

#include "main2.h"


/**
 *  @fn	SemanticNodeBlockModelInstance::SemanticNodeBlockModelInstance(const SyntaxTreeNode *modelI
	*   nstanceNodeParent, SemanticNode *parent)
 *
 *  @brief	Constructor.
 *
 *  @author	Nikola Novak
 *  @date	6/24/2009
 *
 *  @param	advanceNodeParent	If non-null, the advance node parent.
 *  @param	parent				If non-null, the parent.
 */
SemanticNodeBlockModelInstance::SemanticNodeBlockModelInstance(const SyntaxTreeNode *modelInstanceNodeParent, SemanticNode *parent) : SemanticNode(parent), LabeledNode(modelInstanceNodeParent->Nodes->GetData(0)) {
	const SyntaxTreeNode *theNode = modelInstanceNodeParent->Nodes->GetData(1)->Nodes->GetData(0);
	bool full = (theNode->Production == Gr_ModelInstanceBlock__model_Name_spLPar_Arguments_spRPar_spSemiCol);
	if (full) name = flattenNamePeriodAdd(*theNode->Nodes->GetData(1));
	else name = flattenNamePeriodAdd(*theNode->Nodes->GetData(0));
}
/**
 *  @fn	std::string SemanticNodeBlockModelInstance::getName(void)
 *
 *  @brief	Gets the name.
 *
 *  @author	Nikola Novak
 *  @date	6/26/2009
 *
 *  @return	The name.
 */
std::string SemanticNodeBlockModelInstance::getName(void) {
	return name;
}

/**
 *  @fn	void SemanticNodeBlockModelInstance::setParameters(std::vector<SemanticNodeExpression *> par
 *  	ams)
 *
 *  @brief	Sets the parameters.
 *
 *  @author	Nikola Novak
 *  @date	6/26/2009
 *
 *  @param	params	If non-null, options for controlling the operaation.
 */
void SemanticNodeBlockModelInstance::addParameters(std::vector<SemanticNodeExpression *> params) {
	for (std::vector<SemanticNodeExpression *>::iterator i = params.begin(); i != params.end(); ++i) addParameter(*i);
}
/**
 *  @fn	void SemanticNodeBlockModelInstance::addParameter(SemanticNodeExpression *parameter)
 *
 *  @brief	Adds a parameter.
 *
 *  @author	Nikola Novak
 *  @date	6/26/2009
 *
 *  @param	parameter	If non-null, the parameter.
 */
void SemanticNodeBlockModelInstance::addParameter(SemanticNodeExpression *parameter) {
	parameters.push_back(parameter);
}
/**
 *  @fn	std::string SemanticNodeBlockModelInstance::toDebugString(int tab)
 *
 *  @brief	Converts a tab to a debug string.
 *
 *  @author	Nikola Novak
 *  @date	6/25/2009
 *
 *  @param	tab	The tab.
 *
 *  @return	This object as a std::string.
 */
std::string SemanticNodeBlockModelInstance::toDebugString(int tab) {
	std::ostringstream res;
	for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	res << getLabelsDebugString() << ": model " << name << " (" << std::endl;
	for (std::vector<SemanticNodeExpression *>::iterator i = parameters.begin(); i != parameters.end(); ++i) res << ((SemanticNode *)*i)->toDebugString(tab + 1);
	for (int i = 0; i < tab; i++) res << DEBUG_STRING_RAZMAK;
	res << ")" << std::endl;
	return res.str();
}
